package com.lwm.stream;

import com.lwm.entity.Employee;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

/**
 * @author liweimin
 * @version 1.0
 * @date 2020/9/7 10:41
 */
public class SortTest {
    static List<Employee> employeeList = Arrays.asList(
            new Employee("张三", 23, 6433),
            new Employee("张三1", 33, 4433),
            new Employee("张三2", 63, 65333),
            new Employee("张三3", 43, 5333),
            new Employee("张三4", 36, 4233)
    );

    @Test
    public void test01() {
        List<String> list = Arrays.asList("a", "dsa", "ds2a", "dasoh", "ddsl", "oidasy", "tweria00");
        list.stream().sorted().forEach(System.out::println);
    }

    @Test
    public void test02() {
        employeeList.stream().sorted(((o1, o2) -> {
            if (o1.getAge() == o2.getAge())
                return o1.getName().compareTo(o2.getName());
            return Integer.compare(o1.getAge(), o2.getAge());
        })).forEach(System.out::println);
    }
}
